package com.example.chat.model.vo;

import com.example.chat.model.Company;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Optional;

/**
 * @author changwei
 * @date 2022/3/29
 */
@Data
public class CompanyVO extends BaseVO {

    @ApiModelProperty(value = "公司id")
    private String id;

    @ApiModelProperty(value = "公司名称")
    private String name;

    @ApiModelProperty(value = "公司地址")
    private String address;

    @ApiModelProperty(value = "公司地区")
    private String regionId;

    @ApiModelProperty(value = "公司所在地")
    private String regionName;

    public static CompanyVO instance(Company company) {
        CompanyVO companyVO = new CompanyVO();
        companyVO.setId(company.getId());
        companyVO.setName(company.getName());
        companyVO.setRegionId(company.getRegionId());
        companyVO.setAddress(company.getAddress());
        Optional.ofNullable(company.getRegion().getCity()).ifPresent(companyVO::setRegionName);
        return companyVO;
    }
}
